/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.pubsub;

import org.apache.commons.lang.StringUtils;

import com.edi.client.param.EdiClientParam;
import com.edi.client.param.EdiServerParam;
import com.edi.client.plugin.PluginResult;

public abstract class EdiService {	
	protected String appName;
	protected String methodName;
	protected String serviceName;
	// serviceName = appName.methodName
	
	public EdiService(String serviceName){
		this.serviceName = serviceName;
		if (StringUtils.contains(serviceName, ".")){
			appName = StringUtils.substringBefore(serviceName, ".");
			methodName = StringUtils.substringAfter(serviceName, ".");
		}
	}
	
	/**
	 * 执行服务内容，通过判断serviceName是否包含“.”或“.”来确定为脚本型服务还是jar包服务
	 * @return
	 */
	public abstract PluginResult execute(EdiClientParam clientParam)throws Exception;
	
	/**
	 * 执行服务内容，供服务器端直接调用使用
	 * 
	 * @param serverParam
	 * @return
	 * @throws Exception
	 */
	public abstract PluginResult execute(EdiServerParam serverParam) throws Exception;
	
	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}
}
